//
//  SHKViewController.m
//  YsCloudFileManageSDK
//
//  Created by 139994824@qq.com on 02/24/2020.
//  Copyright (c) 2020 139994824@qq.com. All rights reserved.
//

#define  TEST_URL1 @"https:/download1.service.ys100.com/4f0b03bd-6e83-e9f0-21e6-a987f7e35095/20200227102928-539.mp4"


//https:/download2.service.ys100.com/4f0b03bd-6e83-e9f0-21e6-a987f7e35095/20200227102928-539.mp4

//        "url": "https:\/\/download1.service.ys100.com\/4f0b03bd-6e83-e9f0-21e6-a987f7e35095\/20200227102928-539.mp4",
#import "SHKViewController.h"
#import <YsCloudFileManageSDK/YsCloudFileManageSDK.h>

@interface SHKViewController () <TZImagePickerControllerDelegate,UIImagePickerControllerDelegate>

@end

@implementation SHKViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    self.navigationController.navigationBar.translucent = NO;

    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundColor:UIColor.purpleColor];
    [btn setTitle:@"选择图片和视频" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(150, 60));
    }];

    @weakify(self);
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
        // 你可以通过block或者代理，来得到用户选择的照片.
        [imagePickerVc setPickerDelegate:self];
        imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    }];
    

     UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
       [btn1 setBackgroundColor:UIColor.purpleColor];
       [btn1 setTitle:@"下载20个任务" forState:UIControlStateNormal];
       [self.view addSubview:btn1];
       
       [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.mas_equalTo(0);
           make.centerY.mas_equalTo(0).offset(-100);
           make.size.mas_equalTo(CGSizeMake(150, 60));
       }];
    
        [[btn1 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        for (int i = 0; i < 1; i++) {
            [YsCloudFileDownloadManager.shareDownloadManger downloadWithUrl:TEST_URL1 withPara:nil withMethod:@"Get" withCustomCacheName:@"songhongkang" withLastPathComponent:@".mp4"];
            }
       }];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
       [btn2 setBackgroundColor:UIColor.purpleColor];
       [btn2 setTitle:@"文件管理界面" forState:UIControlStateNormal];
       [self.view addSubview:btn2];
       
       [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.mas_equalTo(0);
           make.centerY.mas_equalTo(0).offset(-200);
           make.size.mas_equalTo(CGSizeMake(100, 60));
       }];
    
    [[btn2 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
           @strongify(self);
            NSLog(@"2222");
            NSLog(@"1111");
        YsCloudFileTransmissionVC *transmissionVC = [[YsCloudFileTransmissionVC alloc] init];
        [self.navigationController pushViewController:transmissionVC animated:YES];
//            [YsCloudFileDownloadManager.shareDownloadManger suspendWithDownloadUrl:TEST_URL1];
       }];
    
#if 0
       UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
       [btn3 setBackgroundColor:UIColor.purpleColor];
       [btn3 setTitle:@"恢复任务" forState:UIControlStateNormal];
       [self.view addSubview:btn3];
       
       [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.mas_equalTo(0);
           make.centerY.mas_equalTo(0).offset(-300);
           make.size.mas_equalTo(CGSizeMake(100, 60));
       }];
    
    [[btn3 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
           @strongify(self);
            NSLog(@"2222");
            NSLog(@"1111");
        [YsCloudFileDownloadManager.shareDownloadManger resumeWithdownloadUrl:TEST_URL1];
       }];
#endif
    
}

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos
{
    
    NSLog(@"1111111");
    [photos enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        [YsUploadManager.shareYsUploadManager uploadWithImage:obj withPara:nil withMethod:@"Post" withLastPathComponent:@".png"];
    }];
}

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(PHAsset *)asset {

    // open this code to send video / 打开这段代码发送视频
    [[TZImageManager manager] getVideoOutputPathWithAsset:asset presetName:AVAssetExportPresetHighestQuality success:^(NSString *outputPath) {
        // NSData *data = [NSData dataWithContentsOfFile:outputPath];
        NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
        // Export completed, send video here, send by outputPath or NSData
        // 导出完成，在这里写上传代码，通过路径或者通过NSData上传
                
        [YsUploadManager.shareYsUploadManager uploadWithPath:outputPath withPara:nil withMethod:@"Post" withLastPathComponent:@".mp4"];
        
    } failure:^(NSString *errorMessage, NSError *error) {
        NSLog(@"视频导出失败:%@,error:%@",errorMessage, error);
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//   NSString *path1 = [[NSBundle mainBundle] pathForResource:@"video-2020-02-26-11:52:50-094" ofType:@".mp4"];
//    NSString *path2 = [[NSBundle mainBundle] pathForResource:@"video-2020-02-26-11:52:53-982" ofType:@".mp4"];
//
//    NSString *path3 = [[NSBundle mainBundle] pathForResource:@"video-2020-02-25-19:49:51-698" ofType:@".mp4"];
//    NSString *str1 =  [YsFileUtil readDataWithfilePath:path1].md5String;
//    NSLog(@"%@",str1);
//    NSString *str2 =  [YsFileUtil readDataWithfilePath:path2].md5String;
//    NSLog(@"%@",str2);
//    NSString *str3 =  [YsFileUtil readDataWithfilePath:path3].md5String;
//    NSLog(@"%@",str3);
//
    
//    YsUploadManager.shareYsUploadManager.modelArray;
    
#if 0
    [YsCloudFileDownloadManager.shareDownloadManger downloadWithUrl:TEST_URL1 withPara:nil withMethod:@"Get" withCustomCacheName:@"songhongkang" withLastPathComponent:@".mp4"];
#else
//    YsCloudFileTransmissionVC *transmissionVC = [[YsCloudFileTransmissionVC alloc] init];
//    [self.navigationController pushViewController:transmissionVC animated:YES];
#endif
}

@end
